package com.open.capacity.finance.controller;

import java.util.List;
import java.util.Map;

import com.open.capacity.commons.Result;
import com.open.capacity.finance.service.impl.AuditModelActuator3ServiceImpl;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.finance.entity.SourceFileImport;
import com.open.capacity.finance.service.SourceFileImportService;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 审计数据源文件导入
 *
 * @author
 * @email
 * @date 2023-02-01 17:04:11
 */
@RestController
@RequestMapping("sourcefileimports")
@Api(tags = "审计数据源文件导入")
public class SourceFileImportController {

    @Autowired
    private SourceFileImportService sourceFileImportService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('source_file_import:sourcefileimport:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = sourceFileImportService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('source_file_import:sourcefileimport:list')")
    public Result findById(String id) {
        return Result.succeed(sourceFileImportService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('source_file_import:sourcefileimport:save')")
    public Result save(@RequestBody @Valid SourceFileImport sourceFileImport, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            sourceFileImportService.save(sourceFileImport);
        } else {
            sourceFileImport.setId(Long.parseLong(keyValue));
            sourceFileImportService.update(sourceFileImport);
        }

        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('source_file_import:sourcefileimport:delete')")
    public Result delete(@PathVariable String id) {
        sourceFileImportService.delete(id);
        return Result.succeed("删除成功");
    }

}
